<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/util/benchmark.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/util</a> - benchmark.cpp<span style="font-size: 80%;"> (source / <a href="benchmark.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">58</td>
            <td class="headerCovTableEntry">86</td>
            <td class="headerCovTableEntryLo">67.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">12</td>
            <td class="headerCovTableEntry">15</td>
            <td class="headerCovTableEntryMed">80.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;boost/date_time/posix_time/posix_time.hpp&gt;</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : #include &quot;caffe/common.hpp&quot;
<span class="lineNum">       4 </span>            : #include &quot;caffe/util/benchmark.hpp&quot;
<span class="lineNum">       5 </span>            : 
<a name="6"><span class="lineNum">       6 </span>            : namespace caffe {</a>
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span><span class="lineCov">      24215 : Timer::Timer()</span>
<span class="lineNum">       9 </span>            :     : initted_(false),
<span class="lineNum">      10 </span>            :       running_(false),
<span class="lineNum">      11 </span><span class="lineCov">      24215 :       has_run_at_least_once_(false) {</span>
<span class="lineNum">      12 </span><span class="lineCov">      24215 :   Init();</span>
<a name="13"><span class="lineNum">      13 </span><span class="lineCov">      24215 : }</span></a>
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span><span class="lineCov">      48430 : Timer::~Timer() {</span>
<span class="lineNum">      16 </span><span class="lineCov">      24215 :   if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">      17 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      18 </span>            :     CUDA_CHECK(cudaEventDestroy(start_gpu_));
<span class="lineNum">      19 </span>            :     CUDA_CHECK(cudaEventDestroy(stop_gpu_));
<span class="lineNum">      20 </span>            : #else
<span class="lineNum">      21 </span><span class="lineNoCov">          0 :     NO_GPU;</span>
<span class="lineNum">      22 </span>            : #endif
<span class="lineNum">      23 </span>            :   }
<a name="24"><span class="lineNum">      24 </span><span class="lineCov">      24215 : }</span></a>
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span><span class="lineCov">        101 : void Timer::Start() {</span>
<span class="lineNum">      27 </span><span class="lineCov">        101 :   if (!running()) {</span>
<span class="lineNum">      28 </span><span class="lineCov">        101 :     if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">      29 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      30 </span>            :       CUDA_CHECK(cudaEventRecord(start_gpu_, 0));
<span class="lineNum">      31 </span>            : #else
<span class="lineNum">      32 </span><span class="lineNoCov">          0 :       NO_GPU;</span>
<span class="lineNum">      33 </span>            : #endif
<span class="lineNum">      34 </span>            :     } else {
<span class="lineNum">      35 </span><span class="lineCov">        101 :       start_cpu_ = boost::posix_time::microsec_clock::local_time();</span>
<span class="lineNum">      36 </span>            :     }
<span class="lineNum">      37 </span><span class="lineCov">        101 :     running_ = true;</span>
<span class="lineNum">      38 </span><span class="lineCov">        101 :     has_run_at_least_once_ = true;</span>
<span class="lineNum">      39 </span>            :   }
<a name="40"><span class="lineNum">      40 </span><span class="lineCov">        101 : }</span></a>
<span class="lineNum">      41 </span>            : 
<span class="lineNum">      42 </span><span class="lineCov">        100 : void Timer::Stop() {</span>
<span class="lineNum">      43 </span><span class="lineCov">        100 :   if (running()) {</span>
<span class="lineNum">      44 </span><span class="lineCov">        100 :     if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">      45 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      46 </span>            :       CUDA_CHECK(cudaEventRecord(stop_gpu_, 0));
<span class="lineNum">      47 </span>            : #else
<span class="lineNum">      48 </span><span class="lineNoCov">          0 :       NO_GPU;</span>
<span class="lineNum">      49 </span>            : #endif
<span class="lineNum">      50 </span>            :     } else {
<span class="lineNum">      51 </span><span class="lineCov">        100 :       stop_cpu_ = boost::posix_time::microsec_clock::local_time();</span>
<span class="lineNum">      52 </span>            :     }
<span class="lineNum">      53 </span><span class="lineCov">        100 :     running_ = false;</span>
<span class="lineNum">      54 </span>            :   }
<span class="lineNum">      55 </span><span class="lineCov">        100 : }</span>
<a name="56"><span class="lineNum">      56 </span>            : </a>
<span class="lineNum">      57 </span>            : 
<span class="lineNum">      58 </span><span class="lineNoCov">          0 : float Timer::MicroSeconds() {</span>
<span class="lineNum">      59 </span><span class="lineNoCov">          0 :   if (!has_run_at_least_once()) {</span>
<span class="lineNum">      60 </span><span class="lineNoCov">          0 :     LOG(WARNING) &lt;&lt; &quot;Timer has never been run before reading time.&quot;;</span>
<span class="lineNum">      61 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">      62 </span>            :   }
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :   if (running()) {</span>
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :     Stop();</span>
<span class="lineNum">      65 </span>            :   }
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :   if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">      67 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      68 </span>            :     CUDA_CHECK(cudaEventSynchronize(stop_gpu_));
<span class="lineNum">      69 </span>            :     CUDA_CHECK(cudaEventElapsedTime(&amp;elapsed_milliseconds_, start_gpu_,
<span class="lineNum">      70 </span>            :                                     stop_gpu_));
<span class="lineNum">      71 </span>            :     // Cuda only measure milliseconds
<span class="lineNum">      72 </span>            :     elapsed_microseconds_ = elapsed_milliseconds_ * 1000;
<span class="lineNum">      73 </span>            : #else
<span class="lineNum">      74 </span><span class="lineNoCov">          0 :       NO_GPU;</span>
<span class="lineNum">      75 </span>            : #endif
<span class="lineNum">      76 </span>            :   } else {
<span class="lineNum">      77 </span><span class="lineNoCov">          0 :     elapsed_microseconds_ = (stop_cpu_ - start_cpu_).total_microseconds();</span>
<span class="lineNum">      78 </span>            :   }
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :   return elapsed_microseconds_;</span>
<a name="80"><span class="lineNum">      80 </span>            : }</a>
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span><span class="lineCov">        100 : float Timer::MilliSeconds() {</span>
<span class="lineNum">      83 </span><span class="lineCov">        100 :   if (!has_run_at_least_once()) {</span>
<span class="lineNum">      84 </span><span class="lineNoCov">          0 :     LOG(WARNING) &lt;&lt; &quot;Timer has never been run before reading time.&quot;;</span>
<span class="lineNum">      85 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">      86 </span>            :   }
<span class="lineNum">      87 </span><span class="lineCov">        100 :   if (running()) {</span>
<span class="lineNum">      88 </span><span class="lineCov">        100 :     Stop();</span>
<span class="lineNum">      89 </span>            :   }
<span class="lineNum">      90 </span><span class="lineCov">        100 :   if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">      91 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      92 </span>            :     CUDA_CHECK(cudaEventSynchronize(stop_gpu_));
<span class="lineNum">      93 </span>            :     CUDA_CHECK(cudaEventElapsedTime(&amp;elapsed_milliseconds_, start_gpu_,
<span class="lineNum">      94 </span>            :                                     stop_gpu_));
<span class="lineNum">      95 </span>            : #else
<span class="lineNum">      96 </span><span class="lineNoCov">          0 :       NO_GPU;</span>
<span class="lineNum">      97 </span>            : #endif
<span class="lineNum">      98 </span>            :   } else {
<span class="lineNum">      99 </span><span class="lineCov">        100 :     elapsed_milliseconds_ = (stop_cpu_ - start_cpu_).total_milliseconds();</span>
<span class="lineNum">     100 </span>            :   }
<span class="lineNum">     101 </span><span class="lineCov">        100 :   return elapsed_milliseconds_;</span>
<a name="102"><span class="lineNum">     102 </span>            : }</a>
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span><span class="lineCov">        100 : float Timer::Seconds() {</span>
<span class="lineNum">     105 </span><span class="lineCov">        100 :   return MilliSeconds() / 1000.;</span>
<a name="106"><span class="lineNum">     106 </span>            : }</a>
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span><span class="lineCov">      24215 : void Timer::Init() {</span>
<span class="lineNum">     109 </span><span class="lineCov">      24215 :   if (!initted()) {</span>
<span class="lineNum">     110 </span><span class="lineCov">      24215 :     if (Caffe::mode() == Caffe::GPU) {</span>
<span class="lineNum">     111 </span>            : #ifndef CPU_ONLY
<span class="lineNum">     112 </span>            :       CUDA_CHECK(cudaEventCreate(&amp;start_gpu_));
<span class="lineNum">     113 </span>            :       CUDA_CHECK(cudaEventCreate(&amp;stop_gpu_));
<span class="lineNum">     114 </span>            : #else
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :       NO_GPU;</span>
<span class="lineNum">     116 </span>            : #endif
<span class="lineNum">     117 </span>            :     }
<span class="lineNum">     118 </span><span class="lineCov">      24215 :     initted_ = true;</span>
<span class="lineNum">     119 </span>            :   }
<a name="120"><span class="lineNum">     120 </span><span class="lineCov">      24215 : }</span></a>
<span class="lineNum">     121 </span>            : 
<span class="lineNum">     122 </span><span class="lineCov">      24214 : CPUTimer::CPUTimer() {</span>
<span class="lineNum">     123 </span><span class="lineCov">      24214 :   this-&gt;initted_ = true;</span>
<span class="lineNum">     124 </span><span class="lineCov">      24214 :   this-&gt;running_ = false;</span>
<span class="lineNum">     125 </span><span class="lineCov">      24214 :   this-&gt;has_run_at_least_once_ = false;</span>
<a name="126"><span class="lineNum">     126 </span><span class="lineCov">      24214 : }</span></a>
<span class="lineNum">     127 </span>            : 
<span class="lineNum">     128 </span><span class="lineCov">    1713219 : void CPUTimer::Start() {</span>
<span class="lineNum">     129 </span><span class="lineCov">    1713219 :   if (!running()) {</span>
<span class="lineNum">     130 </span><span class="lineCov">    1713219 :     this-&gt;start_cpu_ = boost::posix_time::microsec_clock::local_time();</span>
<span class="lineNum">     131 </span><span class="lineCov">    1713219 :     this-&gt;running_ = true;</span>
<span class="lineNum">     132 </span><span class="lineCov">    1713219 :     this-&gt;has_run_at_least_once_ = true;</span>
<span class="lineNum">     133 </span>            :   }
<a name="134"><span class="lineNum">     134 </span><span class="lineCov">    1713219 : }</span></a>
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span><span class="lineCov">    1725326 : void CPUTimer::Stop() {</span>
<span class="lineNum">     137 </span><span class="lineCov">    1725326 :   if (running()) {</span>
<span class="lineNum">     138 </span><span class="lineCov">    1713219 :     this-&gt;stop_cpu_ = boost::posix_time::microsec_clock::local_time();</span>
<span class="lineNum">     139 </span><span class="lineCov">    1713219 :     this-&gt;running_ = false;</span>
<span class="lineNum">     140 </span>            :   }
<a name="141"><span class="lineNum">     141 </span><span class="lineCov">    1725326 : }</span></a>
<span class="lineNum">     142 </span>            : 
<span class="lineNum">     143 </span><span class="lineNoCov">          0 : float CPUTimer::MilliSeconds() {</span>
<span class="lineNum">     144 </span><span class="lineNoCov">          0 :   if (!has_run_at_least_once()) {</span>
<span class="lineNum">     145 </span><span class="lineNoCov">          0 :     LOG(WARNING) &lt;&lt; &quot;Timer has never been run before reading time.&quot;;</span>
<span class="lineNum">     146 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">     147 </span>            :   }
<span class="lineNum">     148 </span><span class="lineNoCov">          0 :   if (running()) {</span>
<span class="lineNum">     149 </span><span class="lineNoCov">          0 :     Stop();</span>
<span class="lineNum">     150 </span>            :   }
<span class="lineNum">     151 </span><span class="lineNoCov">          0 :   this-&gt;elapsed_milliseconds_ = (this-&gt;stop_cpu_ -</span>
<span class="lineNum">     152 </span><span class="lineNoCov">          0 :                                 this-&gt;start_cpu_).total_milliseconds();</span>
<span class="lineNum">     153 </span><span class="lineNoCov">          0 :   return this-&gt;elapsed_milliseconds_;</span>
<a name="154"><span class="lineNum">     154 </span>            : }</a>
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span><span class="lineCov">    1701112 : float CPUTimer::MicroSeconds() {</span>
<span class="lineNum">     157 </span><span class="lineCov">    1701112 :   if (!has_run_at_least_once()) {</span>
<span class="lineNum">     158 </span><span class="lineNoCov">          0 :     LOG(WARNING) &lt;&lt; &quot;Timer has never been run before reading time.&quot;;</span>
<span class="lineNum">     159 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">     160 </span>            :   }
<span class="lineNum">     161 </span><span class="lineCov">    1701112 :   if (running()) {</span>
<span class="lineNum">     162 </span><span class="lineCov">    1701112 :     Stop();</span>
<span class="lineNum">     163 </span>            :   }
<span class="lineNum">     164 </span><span class="lineCov">    1701112 :   this-&gt;elapsed_microseconds_ = (this-&gt;stop_cpu_ -</span>
<span class="lineNum">     165 </span><span class="lineCov">    1701112 :                                 this-&gt;start_cpu_).total_microseconds();</span>
<span class="lineNum">     166 </span><span class="lineCov">    1701112 :   return this-&gt;elapsed_microseconds_;</span>
<a name="167"><span class="lineNum">     167 </span>            : }</a>
<span class="lineNum">     168 </span>            : 
<span class="lineNum">     169 </span><span class="lineCov">          2 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
